package com.shengyin.ec.model.dao.companyorder;

import java.io.Serializable;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Iterator;
import java.util.List;

import org.hibernate.Criteria;
import org.hibernate.LockMode;
import org.hibernate.Session;
import org.hibernate.criterion.DetachedCriteria;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.shengyin.ec.model.dao.BaseDaoImpl;
import com.shengyin.ec.model.entity.CompanyOrder;
import com.shengyin.ec.model.entity.Goods;
import com.shengyin.ec.model.entity.Orders;
import com.shengyin.ec.service.order.OrderService;

@Repository("companyOrderDao")

public class CompanyOrderDaoImpl extends BaseDaoImpl<CompanyOrder> implements CompanyOrderDao {

	@Autowired 
	OrderService orderService;
	
	public List<CompanyOrder> getCompanyOrderList(){
		return super.loadAll();
	}
	
	public List<CompanyOrder> getCompanyOrderList(int offset,int pageSize){
		return super.findByPage("from CompanyOrder companyOrder", offset, pageSize);
	}
	
	public Long getTotal(){
		return (Long) super.find("select count(*) from CompanyOrder").get(0);
	}
	
	public CompanyOrder getCompanyOrderById(String id){
		return (CompanyOrder) super.find("from CompanyOrder c where c.id='"+id+"'").get(0);
	}
	
	public void deleteSelectedOrders(Long idsl[]){
		CompanyOrder orders=null;
		Orders orders1=null;
		List<CompanyOrder> companyOrdersList=new ArrayList<CompanyOrder>(0);
		for(long id:idsl)
		{
			orders=super.get(id);
			orderService.deleteRelateOrder(orders.getOrderId());
			companyOrdersList.add(orders);
		}
		super.deleteAll(companyOrdersList);
	}
	
	public void updateComState(CompanyOrder companyOrder){
		super.update(companyOrder);
	}
/*	public List<CompanyOrder> getCompanyOrderListById(String orderId,int offset,int pageSize){
		return super.findByPage("from CompanyOrder c where c.orderId="+orderId, offset, pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderById(String orderId){
		return super.find("from CompanyOrder c where c.orderId="+orderId);
	}
	
	public List<CompanyOrder> getCompanyOrderListByState(String orderState, int offset, int pageSize){
		return super.findByPage("from CompanyOrder c where c.orderState="+orderState,offset,pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderByState(String orderState){
		return super.find("from CompanyOrder c where c.orderState="+orderState);
	}
	
	public List<CompanyOrder> getCompanyOrderListByBE(String beginTime,String endTime,int offset, int pageSize){
		return super.findByPage("from CompanyOrder c where c.createDate>="+beginTime+"and c.createDate<="+endTime, offset, pageSize);
	}
	
	public List<CompanyOrder> getCompanyOrderByBE(String beginTime,String endTime){
		return super.find("from CompanyOrder c where c.createDate>="+beginTime+"and c.createDate<="+endTime);
	}
	
    public List<CompanyOrder> getCompanyOrderListByCompany(String company,int offset, int pageSize){
    	return super.findByPage("from CompanyOrder c where c.company like '%"+company+"%'",offset,pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByCompany(String company){
		return super.find("from CompanyOrder c where c.company like '%"+company+"%'");
	}
	
    public List<CompanyOrder> getCompanyOrderListByComStat(String company,String orderState, int offset, int pageSize){
    	return super.findByPage("from CompanyOrder c where c.company like '%"+company+"%' and c.orderState="+orderState, offset, pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComStat(String company, String orderState){
		return super.find("from CompanyOrder c where c.company like '%"+company+"%' and c.orderState="+orderState);
	}
	
    public List<CompanyOrder> getCompanyOrderListByComBE(String company,String beginTime,String endTime, int offset, int pageSize){
    	return super.findByPage("from CompanyOrder c where c.company like '%"+company+"%' and c.createDate>="+beginTime+"and c.createDate<="+endTime, offset, pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComBE(String company, String beginTime,String endTime){
		return super.find("from CompanyOrder c where c.company like '%"+company+"%' and c.createDate>="+beginTime+"and c.createDate<="+endTime);
		
	}
	
    public List<CompanyOrder> getCompanyOrderListByComBEStat(String company,String beginTime,String endTime,String orderState, int offset, int pageSize){
    	return super.findByPage("from CompanyOrder c where c.company like '%"+company+"%' and c.createDate>="+beginTime+"and c.createDate<="+endTime+"and c.orderState="+orderState, offset, pageSize);
    }
	
	public List<CompanyOrder> getCompanyOrderByComBEStat(String company,String beginTime,String endTime,String orderState){
		return super.find("from CompanyOrder c where c.company like '%"+company+"%' and c.createDate>="+beginTime+"and c.createDate<="+endTime+"and c.orderState="+orderState);
	}
	
	public List<CompanyOrder> getCompanyOrderListByBEStat(String beginTime,String endTime,String orderState, int offset, int pageSize){
	    	return super.findByPage("from CompanyOrder c where  c.createDate>="+beginTime+"and c.createDate<="+endTime+"and c.orderState="+orderState, offset, pageSize);

	 }
		
    public List<CompanyOrder> getCompanyOrderByBEStat(String beginTime,String endTime,String orderState){
   	return super.find("from CompanyOrder c where  c.createDate>="+beginTime+"and c.createDate<="+endTime+"and c.orderState="+orderState);

   }*/
}
